package com.just.demo.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RequestMapping("/test")
@RestController
@Slf4j
public class HelloController {

    @RequestMapping("/aa")
    public Mono<String> test() {
        return Mono.just("hello你好");
    }

    public void test1() {
        // Mono.create();
        Mono.just("hello").subscribe();
    }


    @GetMapping("/mono")
    public Mono<Object> mono() {
        return Mono.create(monoSink -> {
            log.info("创建Mono");
            monoSink.success("hello 你好");
        }).doOnSubscribe(subscription -> {
            log.info("观察者{}", subscription);
        })
                .doOnNext(o -> log.info("收到数据后:{}", o));
    }

    @GetMapping("/flux")
    public Flux<String> flux() {
        return Flux.just("hello", "你好", "spring", "boot");
    }

    @PostMapping("/test2")
    public Mono<Object> test2() {
        return Mono.just("this is aa");
    }

    @GetMapping("/getInfo")
    public String getInfo(String name) {
        return "Hello"+name;
    }


}
